#include "DirectLOL/graphicElement/particles/particleemitter.h"


ParticleEmitter::ParticleEmitter() : GraphicElement(0)
{
    frameCount=0;
    nbParticlePulse=10;
    nbFramePulse=10;
    physicOn=1;

}

void ParticleEmitter::DefineParticleType(GLuint type)
{
    particleType=type;
}

void ParticleEmitter::SetPicking(unsigned char x, unsigned char y, unsigned char z)
{

}

void ParticleEmitter::Picking()
{

}

void ParticleEmitter::Display()
{
    if(frameCount%nbFramePulse==0)
    {
        for(int i=0;i<nbParticlePulse;i++)
        {
            Mesh * lolol=new Mesh();

            lolol->translation= new Vectorf(10.0,1.0,10.0);
            lolol->physic= new Physic(lolol->translation);
            lolol->LoadMesh("mesh/cube_tri.obj");

            Vectorf * LOL = new Vectorf(0.0,2000.0, 0.0);

            LOL->x(LOL->x()+rand() % 500 -250);
            LOL->z(LOL->z()+rand() % 500 -250);

            lolol->physic->AddAcceleration(LOL);
            particles.push_back(new Particle(lolol));
        }
    }

    for(int i=0;i<particles.size();i++)
    {
        particles.at(i)->Display();
    }
    DeleteParticles();
   frameCount++;
}

void ParticleEmitter::ResolvePhysic()
{
    for(int i=0;i<particles.size();i++)
    {
        particles.at(i)->particle->physic->Do();
    }
}

void ParticleEmitter::DeleteParticles()
{

    for(int i=0;i<particles.size();i++)
    {

        if(particles.at(i)->frameCount > particles.at(i)->lifeSpan )
        {
            particles.erase(particles.begin()+i);
            i--;
        }
    }
}


